﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace RenShiPinYongBiao
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            ConnectionManager.OpenConnection();
            SqlCommand cmd = new SqlCommand("select * from TUser where FName=@name and FPassword=@password", ConnectionManager.Connection);
            cmd.Parameters.AddWithValue("@name", tbUserName.Text);
            cmd.Parameters.AddWithValue("@password", tbPassword.Text);
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            if (dr.HasRows)
            {
                dr.Read();
                OperatorControl.FUserID = dr["FUserID"].ToString();
                dr.Close();
                new MainForm().Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码错误！");
                dr.Close();
            }
        }


        private void tbUserName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Enter))
            {
                tbPassword.Focus();
            }
        }

        private void tbPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Enter))
            {
                btnLogin.Focus();
            }
        }
    }
}
